home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 11.6 KB | 389 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TblSel.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Table.hpp"
-
- // ----- TablePart Includes -----
-
- #ifndef TBLSEL_H
- #include "TblSel.h"
- #endif
-
- #ifndef TBLPART_H
- #include "TblPart.h"
- #endif
-
- #ifndef TBLPROXY_H
- #include "TblProxy.h"
- #endif
-
- #ifndef TBLFRAME_H
- #include "TblFrame.h"
- #endif
-
- #ifndef TBLLINK_H
- #include "TblLink.h"
- #endif
-
- // ----- ODF Includes -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- //========================================================================================
- // class CTableSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CTableSelection
- //----------------------------------------------------------------------------------------
-
- CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart) :
- FW_CEmbeddingSelection(ev, TRUE, TRUE), // allow publish and subscribe
- fTablePart(tablePart),
- fCell(0,0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::~CTableSelection
- //----------------------------------------------------------------------------------------
-
- CTableSelection::~CTableSelection()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
- {
- return (fTablePart->CellToProxy(ev, fCell) == NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsSelectionOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CTableSelection::IsSelectionOnlyOneProxy(Environment* ev) const
- {
- return fTablePart->CellToProxy(ev, fCell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::CloseSelection(Environment* ev)
- {
- InvalidateSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::ClearSelection(Environment* ev)
- {
- CTableProxy* proxy = fTablePart->CellToProxy(ev, fCell);
- if (proxy)
- {
- fTablePart->AboutToClearCell(ev, fCell); // break existing links before removing the proxy
-
- FW_CPresentationFrameIterator piter(GetPresentation(ev));
- FW_CFrame* frame = piter.First();
- fTablePart->ContentUpdated(ev, frame, kODUnknownUpdate);
-
- //--- Remove the proxy ---
- proxy->DetachEmbeddedFrames(ev);
- fTablePart->RemoveProxy(proxy);
- InvalidateSelection(ev);
- return TRUE;
- }
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::SelectAll(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::InvalidateSelectBorder
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::InvalidateSelectBorder(Environment* ev, const CCell& cell)
- {
- FW_CRect rect;
- fTablePart->FindRect(cell, rect);
- rect.Inset(FW_IntToFixed(-1), FW_IntToFixed(-1));
-
- FW_CAcquiredODShape aqShape1 = ::FW_NewODShape(ev, rect);
-
- rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
-
- {
- FW_CAcquiredODShape aqShape2 = ::FW_NewODShape(ev, rect);
-
- aqShape1->Subtract(ev, aqShape2);
- }
-
- GetPresentation(ev)->Invalidate(ev, aqShape1);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::Select
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::Select(Environment* ev, const CCell& cell, FW_Boolean drawNow)
- {
- if (drawNow)
- {
- // ----- Change the selection feedback for the active frame only -----
- FW_CPresentationFrameIterator ite1(GetPresentation(ev));
- for (CTableFrame* frame = (CTableFrame*)ite1.First(); ite1.IsNotComplete(); frame = (CTableFrame*)ite1.Next())
- if (frame->IsActive(ev))
- {
- FW_CFrameFacetIterator ite(ev, frame);
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CFacetContext fc(ev, facet);
-
- frame->DrawSelectBorder(ev, fc, fCell);
- frame->DrawSelectBorder(ev, fc, cell);
- }
- }
- }
- else
- {
- InvalidateSelectBorder(ev, fCell);
- InvalidateSelectBorder(ev, cell);
- }
-
- CTableProxy* proxy = fTablePart->CellToProxy(ev, fCell);
-
- fCell = cell;
-
- proxy = fTablePart->CellToProxy(ev, fCell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CreateSelectionFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CTableSelection::CreateSelectionFrameShape(Environment* ev)
- {
- FW_CRect rect;
- fTablePart->FindRect(fCell, rect);
-
- ODShape* shape = ::FW_NewODShape(ev, rect);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CTableSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- return ((CTableSelection*)this)->CreateSelectionFrameShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::DoExternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(destinationSU);
- FW_UNUSED(cloneInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::DoInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::DoInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(sourceSU);
- FW_UNUSED(cloneInfo);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::InvalidateSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::InvalidateSelection(Environment* ev)
- {
- FW_CAcquiredODShape aqShape(this->CreateSelectionFrameShape(ev));
- GetPresentation(ev)->Invalidate(ev, aqShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::SelectProxy
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
- {
- CCell cell = proxy->GetCell();
- this->Select(ev, cell, TRUE); // drawNow?
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame, const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground) const
- {
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- CCell cell;
- ETableLoc tl = fTablePart->HitTest(ev, (CTableFrame*)frame, where, cell);
-
- return (tl == kTLCell && fTablePart->CellToProxy(ev, cell) != NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
-
- if (tableFrame->IsGridShown(ev))
- {
- FW_Boolean select = FALSE;
- CCell cell;
-
- if (inEmbeddedFrameBorder)
- {
- FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
- FW_ASSERT(proxy);
-
- cell = ((CTableProxy*)proxy)->GetCell();
- select = TRUE;
- }
- else
- {
- FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- ETableLoc tl = fTablePart->HitTest(ev, tableFrame, where, cell);
-
- select = (tl == kTLCell && cell != GetCell());
- }
-
- if (select)
- Select(ev, cell, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CanSubscribe
- //---------------------------------------------------------------------------------------
- FW_Boolean CTableSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
- {
- setting = kODPasteAsEmbedOnly; // table has no content to merge
-
- // Check whether the selected cell already contains an embedded part.
- // If it doesn't, allow Paste As.
- /* MEB-- what about Drag&Drop? */
- return this->IsEmpty(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsSelectionPublishable
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsSelectionPublishable(Environment* ev)
- {
- FW_Boolean result = fAllowPublish;
-
- if (fAllowPublish)
- {
- // make sure the cell is not a link destination
- CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
- if (linkMgr->CellToSubscribeLink(ev, this->GetCell()))
- result = FALSE;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::DoFindPublisher
- //----------------------------------------------------------------------------------------
- FW_CPublishLink* CTableSelection::DoFindPublisher(Environment* ev) // Override
- {
- CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
- return linkMgr->CellToPublishLink(ev, fCell);
- }
-
-